//
//  GAStream.h
//  testjabber
//
//  Created by imuse on 11-7-8.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//
//#import <CoreServices/CoreServices.h>
#import <CFNetwork/CFNetwork.h>
#import <Foundation/NSStream.h>
#import <Foundation/NSData.h>

typedef enum
{
  kGAStreamStatusComplete = 0,    //创建连接成功
  kGAStreamStatusClose,           //连接关闭
  kGAStreamStatusFailed,          //创建连接失败
  kGAStreamStatusError,           //socket错误
  kGAStreamStatusSystemError,     //系统错误
  kGAStreamStatusData,            //数据包
}GAStreamStatus;

@protocol GAStreamDelegate <NSObject>

@optional
- (void)gaStreamEvent:(GAStreamStatus)anStatus withData:(void*)apData withDataSize:(int)anSize;
@end

@interface GAStream : NSObject {
  ///服务器地址
  NSString *m_pstrServer;
  ///服务器端口
  int      m_nPort;
  ///输入流
  NSInputStream *inStream; 
  ///输入出流
  NSOutputStream *outStream; 
  ///读取数据缓冲
  uint8_t *m_pReadBuffer;
  ///发送数据缓冲区，只在没有发送成功时缓存数据，待发送缓冲状态可写时会把数据发送出去。
  NSMutableData* m_pSendData;
  ///回调委托
  id<GAStreamDelegate> _delegate;
  
}

- (void)closeStream;
- (void)openStream;


//以下为外部调用接口

/**设置委托回调接口
 *
 *  @return
 *  @note 
 */
- (void)setDelegate:(id<GAStreamDelegate>)_d;

/**设置服务器ip和端口
 *
 *  @param char*	apIP    服务器ip域名
 *  @param int    anPort  端口号
 *  @return
 *  @note 
 */
- (void)setServerIPPort:(char*)apServer withPort:(int)anPort;

/**连接到服务器
 *
 *  @return
 *  @note 
 */
- (void)connectToServer;

/**发送数据
 *
 *  @param char*	apSendBuffer    发送数据
 *  @param int    anSize          发送数据大小
 *  @return
 *  @note 
 */
- (int)writeBytes:(char*)apSendBuffer length:(unsigned int)anSize;


@end